<?php

    //Sub Table Class define
    include_once("ClassSub.php");

class ListingDataClass
{
	var $REAgent;
	var $REOffice;
	var $ListDate;
	var $ListPrice;				//SubClass
	var $ExpirationDate;
	var $ShowingInstructions;
	var $ListingType;
	var $Commission;			//SubClass
	var $PublicRemarks;
	
	var $ID;
	
	function AddItemFromXML($XmlArray)
	{
		$Array = $XmlArray->children();
			
	 	$Addr = $Array[0]->children();
		$this->REAgent = $Addr[0];
	 	$Addr = $Array[1]->children();
		$this->REOffice = $Addr[0];
	 	$this->ListDate = $Array[2];
	 	$this->ListPrice = new CurrencyFormatClass;
		$this->ListPrice->AddItemFromXML($Array[3]);
	 	$this->ExpirationDate = $Array[4];
	 	$this->ShowingInstructions = $Array[5];
	 	$this->ListingType = $Array[6];
	 	$this->Commission = new CurrencyFormatClass;
		$this->Commission->AddItemFromXML($Array[7]);
	 	$this->PublicRemarks = $Array[8];
	}
	
	function InsertSQL()
	{
		$this->ListPrice->InsertSQL();
		$this->Commission->InsertSQL();		

		$strSqlCommand = "INSERT INTO ListingData( REAgentID, REOfficeID, ";
		$strSqlCommand .="ListDate, Price, ExpirationDate, ShowingInstructions, ";
		$strSqlCommand .="ListingType, Commission, PublicRemarks) ";
		$strSqlCommand .= "VALUES( '".$this->REAgent."', ";
		$strSqlCommand .= "'".$this->REOffice."', ";
		$strSqlCommand .= "'".$this->ListDate."', ";
		$strSqlCommand .= "'".$this->ListPrice->ID."', ";
		$strSqlCommand .= "'".$this->ExpirationDate."', ";
		$strSqlCommand .= "'".$this->ShowingInstructions."', ";
		$strSqlCommand .= "'".$this->ListingType."', ";
		$strSqlCommand .= "'".$this->Commission->ID."', ";
		$strSqlCommand .= "'".$this->PublicRemarks."') ";
				
		mysql_query($strSqlCommand);
		$this->ID = mysql_insert_id();		
	}
	
	function ModifySQL( $InputID )
	{
		$this->ID = $InputID;

		$strSqlCommand = "SELECT * FROM ListingData ";
		$strSqlCommand .= " WHERE idListingData = '".$this->ID."' ";
		$result = mysql_query($strSqlCommand);
		$rowListingData = @mysql_fetch_array($result);

		$strSqlCommand =  "UPDATE ListingData SET ";
		$strSqlCommand .= "REAgentID='"				.$this->REAgent				."', ";
		$strSqlCommand .= "REOfficeID='"			.$this->REOffice			."', ";
		$strSqlCommand .= "ListDate='"				.$this->ListDate			."', ";
		$strSqlCommand .= "ExpirationDate='"		.$this->ExpirationDate		."', ";
		$strSqlCommand .= "ShowingInstructions='"	.$this->ShowingInstructions	."', ";
		$strSqlCommand .= "ListingType='"			.$this->ListingType			."', ";
		$strSqlCommand .= "PublicRemarks='"			.$this->PublicRemarks		."' ";
		$strSqlCommand .= "WHERE idListingData = ".$this->ID;
		mysql_query($strSqlCommand);

		$this->ListPrice->ModifySQL	( $rowListing["Price"] );
		$this->Commission->ModifySQL( $rowListing["Commission"]);			
	}

}

?>